<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>sline: sline简介</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">sline<span id="projectnumber">&#160;v1.1.1</span>
   </div>
   <div id="projectbrief">This is a shell component.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">载入中...</div>
<div class="SRStatus" id="Searching">搜索中...</div>
<div class="SRStatus" id="NoMatches">未找到</div>
</div>
</div>
</div>
</div>

</div><!-- top -->
<div><div class="header">
  <div class="headertitle"><div class="title">sline简介 </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="autotoc_md1"></a>
功能</h1>
<p>1.支持命令绑定：支持多个参数输入，同时带返回输出。 </p><div class="fragment"><div class="line">int func(int argc,char * argv[])</div>
<div class="line">{</div>
<div class="line">    int i;</div>
<div class="line">    /*code*/</div>
<div class="line">    return 0;</div>
<div class="line">}</div>
<div class="line">SL_CMD_EXPORT(func,&quot;This is a cmd func!&quot;)</div>
</div><!-- fragment --><p> 创建上述形式的函数，并调用 SL_CMD_EXPORT 注册命令。</p>
<p>2.[新增]预制指令绑定，函数原型如下：</p>
<div class="fragment"><div class="line">SL_API int sl_cmd_export_pre(char* name,void * func,char *desc);</div>
</div><!-- fragment --><p> 调用时，直接调用（！注意在注册sl_create()函数之前调用）：</p>
<div class="fragment"><div class="line">sl_cmd_export_pre(&quot;history&quot;,sl_show_his,&quot;Display input history.&quot;);</div>
<div class="line">sl_cmd_export_pre(&quot;help&quot;,sl_show_allcmd,&quot;Display all of cmds.&quot;);</div>
</div><!-- fragment --><p>3.支持历史输入切换：通过安检的上下键检索之前的输入历史。</p>
<p>4.tap键联想提示功能：在没有数据输入时，按下tap键，会显示所有已经注册的指令；当输入一部分指令后按下tap键会自动补全命令。 </p>
<h1><a class="anchor" id="autotoc_md2"></a>
使用</h1>
<p>1.windows端确保安装了gcc环境，然后进入命令行，输入make指令，则会生成sline.exe，双击运行即可。</p>
<p>2.在龙芯2K1000环境下，将文件 <a class="el" href="sline_8c.html" title="sline命令行组件的功能实现">sline.c</a> 与 <a class="el" href="sline_8h.html" title="sline命令行组件的功能实现">sline.h</a> 加入工程文件中； 在程序中对sline进行注册，注册需要两个函数，分别是：</p>
<div class="fragment"><div class="line">/*这部分接口更为与标准C一致*/                      </div>
<div class="line">typedef struct </div>
<div class="line">{</div>
<div class="line">    int (*getc) (void); /*int 为getc的返回值-1 为失败 其余为获得的值*/</div>
<div class="line">    int (*putc) (char); /*int 为putc的返回值-1 为失败 其余为输出的值 char为输出值*/</div>
<div class="line">}sl_register_func_t;</div>
</div><!-- fragment --><p> 先编写对应的接口函数，以LS2K1000裸机环境为例：</p>
<div class="fragment"><div class="line">int putcc(char data)</div>
<div class="line">{</div>
<div class="line">    while (!(UART_REG-&gt;LSR &amp; UART_TRAN_EMPTY)); </div>
<div class="line">    UART_REG-&gt;DATA = data;</div>
<div class="line">    return data;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">/*裸机情况下，getcc函数必须为非组塞式*/</div>
<div class="line">int getcc(void)</div>
<div class="line">{</div>
<div class="line">    if(UART_REG-&gt;LSR &amp; UART_REC_FULL)</div>
<div class="line">    {</div>
<div class="line">        return UART_REG-&gt;DATA &amp; 0xff;</div>
<div class="line">    }</div>
<div class="line">    return -1;</div>
<div class="line">}</div>
</div><!-- fragment --><p> 在程序初始化中，注册sline，sline做了精简，不支持多对象。</p>
<div class="fragment"><div class="line">sl_register_func_t sl_rfunc = {</div>
<div class="line">                                .getc = getcc,</div>
<div class="line">                                .putc = putcc</div>
<div class="line">                                };</div>
<div class="line"> </div>
<div class="line">sl_create( &amp;sl_rfunc);</div>
</div><!-- fragment --><p> 可以再次调用sl_create()，重新注册sline。</p>
<p>注册完成后，裸机可以在状态机中或会反复进入的函数中调用 <a class="el" href="sline_8c.html#a897ba612c938fcc4143db946168f1c8c" title="等待处理命令输入">sl_waitcmd()</a> 函数，保证sline 的正常运行。如果该函数不能被持续调用，会导致功能失效。</p>
<div class="fragment"><div class="line">while(1)</div>
<div class="line">{</div>
<div class="line">    FSM_RUN();</div>
<div class="line">#if CMD_EN</div>
<div class="line">    sl_waitcmd();/*CMD*/</div>
<div class="line">#endif</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6
</small></address>
</body>
</html>
